package Controller.SCServlet;

import Dao.SCDao;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/sc_alter")
public class sc_alter extends HttpServlet {
    SCDao scDao = new SCDao();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String sno = req.getParameter("sno");
        String cno = req.getParameter("cno");
        String grade = req.getParameter("grade");
        if ("未修完".equals(grade)) {
            grade = null;
        }
        scDao.update(sno, cno, grade);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "修改成功");
        resp.getWriter().write(JSON.toJSONString(map));
    }
}
